package cloud.simple.ui.service;

import cloud.simple.ui.model.User;
import cloud.simple.ui.remote.CloudSimpleClient;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiang.orchid@gmail.com
 * @Create 2016-09-29 17:56
 */

@Service
public class UserService {

    @Autowired
    CloudSimpleClient cloudSimpleClient;

    @HystrixCommand(fallbackMethod = "fallbackSearchAll")
    public List<User> readUserInfo() {
        return  cloudSimpleClient.readUserInfo();
    }

    private List<User> fallbackSearchAll() {
        System.out.println("HystrixCommand fallbackMethod handle!");
        List<User> ls = new ArrayList<User>();
        User user = new User();
        user.setUsername("TestHystrixCommand");
        ls.add(user);
        return ls;
    }
}
